<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:c="http://java.sun.com/jsp/jstl/core"
      xmlns:x="http://java.sun.com/jsf/composite/movie"
      xmlns:cc="http://java.sun.com/jsf/composite">

    <cc:interface>
        <cc:attribute name="controller" required="true" />
    </cc:interface>

    <cc:implementation>
        <c:set var="ctrl" value="#{cc.attrs.controller}"/>
       
        <h:outputLabel rendered="#{ctrl.items!=null and ctrl.items.rowCount gt 0}" for="statusSelect" value="Use Status: "/>
        <h:selectOneListbox rendered="#{ctrl.items!=null and ctrl.items.rowCount gt 0}" style="width: 100px;" value="#{ctrl.selectedStatus}"  id="statusSelect" size="1">
            <f:selectItems value="#{statusBackingBean.statuses}"  var="stat" itemLabel="#{stat.movieStatus.toLowerCase()}" itemValue="#{stat.movieStatus}" />
        </h:selectOneListbox>
        <br/><br/>


        <h:dataTable styleClass="overflow-table"  rendered="#{ctrl.items!=null and ctrl.items.rowCount gt 0}" value="#{ctrl.items}" var="item" columnClasses="textalignright, textalignleft, textaligncenter, textalignleft,textaligncenter" rowClasses="odd,even" >
            <c:set var="index" value=" #{ctrl.items.rowIndex + 1}" />
            <h:column>
                <f:facet name="header">#</f:facet>
                #{index}
            </h:column>
            <h:column>
                <f:facet name="header">
                    <x:movieSort sortBy="Title" controll="#{ctrl}" />
                </f:facet>

                <h:outputText value="#{item.movie.title}" escape="false"/>
            </h:column>

            <h:column>
                <f:facet name="header">
                    <x:movieSort sortBy="Year"  controll="#{ctrl}" />
                </f:facet>
                <h:outputText value="#{item.movie.year}" escape="false"/>
            </h:column>

            <h:column>
                <f:facet name="header">
                    <x:movieSort sortBy="Type"  controll="#{ctrl}" />
                </f:facet>
                <h:outputText value="#{item.movie.type.name}"/>
            </h:column>

            <h:column>
                <f:facet name="header">
                    <x:movieSort sortBy="IMDBID"  controll="#{ctrl}" />
                </f:facet>
                <a href="#{item.movie.url}" target="_blank"><h:outputText value="#{item.movie.idForSite}"/></a>
            </h:column>

            <h:column>
                <f:facet name="header">
                    <h:outputText value="Action"/>
                </f:facet>
                <h:commandLink rendered="#{item.id==null}" action="#{ctrl.saveSelectedMovie}"><img src="#{resource['images:add.png']}" alt="add"/></h:commandLink>
                <h:commandLink rendered="#{item.id!=null}" action="#{ctrl.removeSelectedMovie}" ><img src="#{resource['images:remove.png']}" alt="remove"/></h:commandLink>
                &nbsp;<h:commandLink rendered="#{item.id!=null}" action="#{ctrl.changeStatus}" ><img src="#{resource['images:change.png']}" alt="change"/></h:commandLink>
            </h:column>

            <h:column>
                <f:facet name="header">
                    <x:movieSort sortBy="Status" controll="#{ctrl}" />
                </f:facet>
                <h:outputText rendered="#{item.id!=null}" value="#{item.movieStatus.movieStatus.toLowerCase()}" />
            </h:column>

        </h:dataTable>
    </cc:implementation>
</html>

